package com.example.gm.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.gm.entity.ApiResult;
import com.example.gm.service.GmApiService;
import com.example.gm.service.GmJwtService;

import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
@RequestMapping("/api/gm/*")
@CrossOrigin
public class GmApiController {
	@Autowired
	GmJwtService gmJwtService;

	@PostMapping(value = "test", produces = "application/json; charset=UTF-8")
	public Object test() {
		Authentication authentication = gmJwtService.getUserAuth();
		if(authentication==null)return ApiResult.error("Authentication is Null");
		return ApiResult.ok(authentication.getName());
	}
	
}
